/*
 * @Author: xujianxing
 * @Date: 2020-02-16 13:07:59
 * @LastEditors  : xujianxing
 * @LastEditTime : 2020-02-21 13:27:41
 * @Description: file content
 */
var mysql = require("mysql");
var config = require("./config");
var pool = mysql.createPool(config);
pool.on("connection", function(conn) {
  console.log("在pool中建立新的连接", conn.threadId);
});
function query(sql, params) {
  return new Promise((resolve, reject) => {
    pool.query(sql, params, (err, result) => {
      if (err) {
        reject(err);
      } else {
        resolve(result);
      }
    });
  });
}

module.exports = {
  pool,
  query
};
